package o;

import com.huawei.appmarket.service.usercenter.userinfo.bean.CityInfo;
import com.huawei.appmarket.service.usercenter.userinfo.bean.ProvinceInfo;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;

public class emh {
    public static void ˋ(List<ProvinceInfo> list) {
        Closeable openFileOutput;
        Closeable bufferedWriter;
        Throwable th;
        boolean z;
        Closeable closeable = null;
        if (!CollectCheck.isEmpty(list)) {
            eui ॱ;
            try {
                openFileOutput = ContentManager.getInstant().getContext().openFileOutput("area_info", 0);
                try {
                    bufferedWriter = new BufferedWriter(new OutputStreamWriter(openFileOutput, "UTF-8"));
                    int i = 0;
                    while (i < list.size()) {
                        try {
                            String ʻ = dof.ʻ(String.valueOf(i + 11));
                            ˋ(list, i, ʻ, bufferedWriter);
                            List ˋ = ((ProvinceInfo) list.get(i)).ˋ();
                            if (!CollectCheck.isEmpty(ˋ)) {
                                for (int i2 = 0; i2 < ˋ.size(); i2++) {
                                    String ʻ2 = dof.ʻ(String.valueOf(i2 + 11));
                                    ˋ(ˋ, i2, ʻ2, ʻ, bufferedWriter);
                                    List ˋ2 = ((CityInfo) ˋ.get(i2)).ˋ();
                                    if (!CollectCheck.isEmpty(ˋ2)) {
                                        for (int i3 = 0; i3 < ˋ2.size(); i3++) {
                                            ˊ(ˋ2, i3, ʻ, ʻ2, bufferedWriter);
                                        }
                                    }
                                }
                            }
                            i++;
                        } catch (Exception e) {
                            closeable = openFileOutput;
                            openFileOutput = bufferedWriter;
                        } catch (Throwable th2) {
                            th = th2;
                        }
                    }
                    bufferedWriter.flush();
                    z = true;
                    dnw.ˎ(bufferedWriter);
                    dnw.ˎ(openFileOutput);
                } catch (Exception e2) {
                    Closeable closeable2 = openFileOutput;
                    openFileOutput = null;
                    closeable = closeable2;
                    try {
                        Logger.ˋ("AddressWriter", "write area info error");
                        dnw.ˎ(openFileOutput);
                        dnw.ˎ(closeable);
                        z = false;
                        ॱ = emk.ˋ().ॱ();
                        ॱ.ˋ("file_write_completed", z);
                        if (!z) {
                            ॱ.ˎ("last_update_time", System.currentTimeMillis());
                        }
                    } catch (Throwable th3) {
                        bufferedWriter = openFileOutput;
                        openFileOutput = closeable;
                        th = th3;
                        dnw.ˎ(bufferedWriter);
                        dnw.ˎ(openFileOutput);
                        throw th;
                    }
                } catch (Throwable th32) {
                    bufferedWriter = null;
                    th = th32;
                    dnw.ˎ(bufferedWriter);
                    dnw.ˎ(openFileOutput);
                    throw th;
                }
            } catch (Exception e3) {
                openFileOutput = null;
                Logger.ˋ("AddressWriter", "write area info error");
                dnw.ˎ(openFileOutput);
                dnw.ˎ(closeable);
                z = false;
                ॱ = emk.ˋ().ॱ();
                ॱ.ˋ("file_write_completed", z);
                if (!z) {
                    ॱ.ˎ("last_update_time", System.currentTimeMillis());
                }
            } catch (Throwable th322) {
                openFileOutput = null;
                bufferedWriter = null;
                th = th322;
                dnw.ˎ(bufferedWriter);
                dnw.ˎ(openFileOutput);
                throw th;
            }
            ॱ = emk.ˋ().ॱ();
            ॱ.ˋ("file_write_completed", z);
            if (!z) {
                ॱ.ˎ("last_update_time", System.currentTimeMillis());
            }
        }
    }

    private static void ˋ(List<ProvinceInfo> list, int i, String str, BufferedWriter bufferedWriter) throws IOException {
        String ʻ = dof.ʻ(((ProvinceInfo) list.get(i)).ˎ());
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(str).append("0000").append(ʻ);
        ˏ(bufferedWriter, stringBuilder.toString());
    }

    private static void ˋ(List<CityInfo> list, int i, String str, String str2, BufferedWriter bufferedWriter) throws IOException {
        String ʻ = dof.ʻ(((CityInfo) list.get(i)).ॱ());
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(str2).append(str).append("00").append(ʻ);
        ˏ(bufferedWriter, stringBuilder.toString());
    }

    private static void ˊ(List<String> list, int i, String str, String str2, BufferedWriter bufferedWriter) throws IOException {
        String ʻ = dof.ʻ(String.valueOf(i + 11));
        String ʻ2 = dof.ʻ((String) list.get(i));
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(str).append(str2).append(ʻ).append(ʻ2);
        ˏ(bufferedWriter, stringBuilder.toString());
    }

    private static void ˏ(BufferedWriter bufferedWriter, String str) throws IOException {
        bufferedWriter.write(str);
        bufferedWriter.newLine();
    }
}
